package com.lemon.ai.socket.packets.spiritgame.message;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

/**
 * 将后端的文字提示信息转换成XML配置表
 * @author 	林岑
 * @time	2012年9月18日 11:27:38
 *
 */
public class MessageExport {
	public static void main(String[] args) throws FileNotFoundException, IOException {
		
		Properties p = new Properties();
		p.load(new FileReader(new File("res\\MessageProperties.prop")));
		
		StringBuilder s = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r<root>\r");
		String temp = "<item id=xx content=yyy/>";
		
		Map<Integer, String> all = new TreeMap<Integer, String>();
		for (Object o : p.keySet()) 
			all.put(Integer.parseInt(o + ""), p.getProperty(o.toString()));
		
		for (Integer i : all.keySet()) {
			s.append("\t" + temp.replace("xx", i + "").replace("yyy", "\"" + all.get(i) + "\""));
			s.append("\r");
		}
		
		s.append("</root>");
		
		File f = new File("test/message/messages.xml");
		FileWriter fw = new FileWriter(f);
		System.out.println(s);
		fw.write(s.toString());
		fw.flush();
		System.out.println("导出成功, 生成文件在当前包下");
	}
}
